/**
 * 订单相关API服务
 */
import api from './index';
import { ApiResponse, Order, PaginationData } from './types';

/**
 * 创建订单
 */
export interface CreateOrderParams {
  hotelId: string;
  hotelName: string;
  roomId: string;
  roomName: string;
  checkInDate: string;
  checkOutDate: string;
  nights: number;
  guests: number;
  guestName: string;
  contactPhone: string;
  totalPrice: number;
  couponId?: string;
}

export const createOrder = (params: CreateOrderParams): Promise<ApiResponse<{ orderId: string }>> => {
  return api.post('/orders', params);
};

/**
 * 获取订单列表
 */
export interface GetOrdersParams {
  status?: 'pending' | 'confirmed' | 'cancelled' | 'completed';
  page?: number;
  pageSize?: number;
}

export const getOrders = (params?: GetOrdersParams): Promise<ApiResponse<PaginationData<Order>>> => {
  return api.get('/orders', { params });
};

/**
 * 获取订单详情
 */
export const getOrderDetail = (id: string): Promise<ApiResponse<Order>> => {
  return api.get(`/orders/${id}`);
};

/**
 * 取消订单
 */
export const cancelOrder = (id: string): Promise<ApiResponse<null>> => {
  return api.put(`/orders/${id}/cancel`);
};

/**
 * 支付订单
 */
export const payOrder = (id: string, paymentMethod: string): Promise<ApiResponse<null>> => {
  return api.put(`/orders/${id}/pay`, { paymentMethod });
};

/**
 * 获取用户订单列表
 */
export const getUserOrders = (params?: {
  status?: 'all' | 'pending' | 'confirmed' | 'cancelled' | 'completed';
  page?: number;
  pageSize?: number;
}): Promise<ApiResponse<PaginationData<Order>>> => {
  return api.get('/user/orders', { params });
}; 